package cn.stylefeng.guns.sys.modular.system.db6.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.db6.entity.SysDict;
import cn.stylefeng.guns.sys.modular.system.db6.mapper.SysDictMapper;
import cn.stylefeng.guns.sys.modular.system.db6.model.params.SysDictParam;
import cn.stylefeng.guns.sys.modular.system.db6.model.result.SysDictResult;
import  cn.stylefeng.guns.sys.modular.system.db6.service.SysDictService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 基础字典 服务实现类
 * </p>
 *
 * @author wjk
 * @since 2021-09-30
 */
@Service
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements SysDictService {

    @Override
    public void add(SysDictParam param){
        SysDict entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(SysDictParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(SysDictParam param){
        SysDict oldEntity = getOldEntity(param);
        SysDict newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public SysDictResult findBySpec(SysDictParam param){
        return null;
    }

    @Override
    public List<SysDictResult> findListBySpec(SysDictParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(SysDictParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<SysDict> findListAll() {
        return this.list();
    }
    /**
     * 获取允许设置考勤天数的列表
     *
     * @author wjk
     * @Date 2021-09-30
     */
    @Override
    public List<SysDict> getSysDictAttendAudit(){
        return this.baseMapper.getSysDictAttendAudit();
    }
    /**
     * 获取允许设置考勤天数最后几天
     *
     * @author wjk
     * @Date 2021-09-30
     */
    @Override
    public List<SysDict> getSysDictAttendAuditLastDay() {
        return this.baseMapper.getSysDictAttendAuditLastDay();
    }

    private Serializable getKey(SysDictParam param){
        return param.getDictId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private SysDict getOldEntity(SysDictParam param) {
        return this.getById(getKey(param));
    }

    private SysDict getEntity(SysDictParam param) {
        SysDict entity = new SysDict();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
